package com.nari.ysphd.ui;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.jeremyfeinstein.okhttputil.callback.StringCallback;
import com.jeremyfeinstein.utils.ConfigUtil;
import com.jeremyfeinstein.utils.YCHSInstance;
import com.jeremyfeinstein.utils.YCHSWebSocketAPI;
import com.jeremyfeinstein.utils.YCHShttpAPI;
import com.nari.ysphd.MyApp;
import com.nari.ysphd.R;

import nari.mip.core.Platform;
import okhttp3.Call;

public class UserActivity extends BaseActivity {

    private TextView name, department;
    private Button logout;
    private ImageView user_back;
    private CheckBox msg;
    private AlertDialog loginOutDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }


    protected void setContentView() {
        // TODO Auto-generated method stub
        setContentView(R.layout.activity_user);
    }

    protected void initViews() {
        // TODO Auto-generated method stub
        name = (TextView) findViewById(R.id.name);
        department = (TextView) findViewById(R.id.department);
        logout = (Button) findViewById(R.id.user_logout);
        user_back = (ImageView) findViewById(R.id.user_back);
        msg = (CheckBox) findViewById(R.id.getmsg);

    }

    protected void initListeners() {
        // TODO Auto-generated method stub
        logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                logoutDialog();
            }
        });

        user_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                startActivity(new Intent(UserActivity.this, MeetingListUI.class));
                finish();
            }
        });

        msg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ConfigUtil.getInstance().setMsg(isChecked);
//                    showErrorWithStatus(ConfigUtil.getApp().getMsg()+"");
                } else {
                    ConfigUtil.getInstance().setMsg(isChecked);
//                    showErrorWithStatus(ConfigUtil.getApp().getMsg()+"");
                }
            }
        });
    }

    private void logoutDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(UserActivity.this);
        builder.setMessage("是否要退出登录？");
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                logout();
                dialog.dismiss();
                finish();
            }
        });
        loginOutDialog = builder.create();
        loginOutDialog.show();
    }

    protected void initData() {
        if (null != name) {
            name.setText(com.nari.ysphd.util.TextUtils.desensitization(YCHSInstance.getInstance().getLoginUser().getLOGIN_NAME()));
        }
        department.setText(YCHSInstance.getInstance().getLoginUser().getDEP_NAME());
        msg.setChecked(ConfigUtil.getInstance().getMsg());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
